import Vue from 'vue'
//import { State } from '@/store'
import { Store, CommitOptions, DispatchOptions } from 'vuex/types/index';
import { State } from '@/plugin/types/store'

/** 定义一个VUE扩展，以用于注入 $state */
const TypedState = {  // define a Vue plugin. See https://vuejs.org/v2/guide/plugins.html
    install(Vue: any) {  // For simplify, didn't pass 'State' via options
        Object.defineProperty(
            Vue.prototype,
            '$state',
            {  // Add a global getter 'this.$state' in vm
                get(): State { return this.$store.state as State }
            }
        );
        Object.defineProperty(
            Vue.prototype,
            '$storeTS',
            {  // Add a global getter 'this.$state' in vm
                get(): Store<State> { return this.$store as Store<State> }
            }
        );
    }
}

Vue.use(TypedState)